package com.qf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.DtsOrder;
import com.qf.vo.DayStatis;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author zhaojian
 * @since 2021-05-12
 */
public interface DtsOrderMapper extends BaseMapper<DtsOrder> {

    /**
     * 日期和对应的订单总额, 订单笔数
     * @param statisDaysRang
     * @return
     */
    @Select("SELECT\n" +
            "\tsum( actual_price ) AS amts,\n" +
            "\tDATE_FORMAT( add_time, '%Y-%m-%d' ) AS dayStr,\n" +
            "\tcount( 1 ) AS cnts \n" +
            "FROM\n" +
            "\tdts_order \n" +
            "WHERE\n" +
            "\tDATE_FORMAT( add_time, '%Y-%m-%d' ) > DATE_FORMAT( DATE_ADD( NOW(), INTERVAL - #{statisDaysRang} DAY ), '%Y-%m-%d' ) \n" +
            "GROUP BY\n" +
            "\tDATE_FORMAT(\n" +
            "\t\tadd_time,\n" +
            "\t'%Y-%m-%d') ")
    List<DayStatis> findOrderDayStatis(@Param("statisDaysRang") int statisDaysRang);


}
